//
//  OrderMananger.m
//  YIChuSeller
//
//  Created by 田小椿 on 2019/1/2.
//  Copyright © 2019年 xiangshengjun. All rights reserved.
//

#import "OrderAndUploadPhotoMananger.h"
#import "OrderMessageModel.h"
@implementation OrderAndUploadPhotoMananger
+ (void)selectShopOrderWithStoreID:(NSString *)storeId state:(NSString *)stateStr page:(NSString *)page success:(CompleteHandle)success fail:(CompleteHandle)fail{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"SELECT_STORE_ORDE",
                @"parameters":@{
                        @"storeId":storeId,
                        @"state":stateStr,
                        @"page":page
                        }
                };
    [HttpHelper Post:@"ycs/Orde/Orde.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD dismiss];
            NSArray *contentArr = responseObject[@"result"][@"ords"];
            if (!contentArr.count) {
                [SVProgressHUD showImage:nil status:@"暂无更多数据"];
            }
            NSMutableArray * dataArray = [NSMutableArray array];
            for (NSDictionary *dict in contentArr) {
                OrderMessageModel * model = [OrderMessageModel mj_objectWithKeyValues:dict];
                if (![model.state isEqualToString:@"4"]) {//移除已完成
                    [dataArray addObject:model];
                }
            }
            success(dataArray);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)ChangeShopOrderState:(NSString *)stateStr oNumber:(NSString *)oNumberStr success:(CompleteHandle)success fail:(CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"提交中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"UPDATE_ORDE_STATE",
                @"parameters":@{
                        @"oNumber":oNumberStr,
                        @"state":stateStr,
                        }
                };
    [HttpHelper Post:@"ycs/Orde/Orde.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"修改成功"];
            success(responseObject);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"修改失败"];
    }];
}
+ (void)selectShopOrderAllMessageWithONumber:(NSString *)oNumberStr  success:(CompleteHandle)success fail:(CompleteHandle)fail{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_ORDE_FINDORDEORID",
                @"parameters":@{
                        @"oNumber":oNumberStr
                        }
                };
    [HttpHelper Post:@"ycs/Orde/Orde.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
             [SVProgressHUD dismiss];
            success(responseObject);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}
+ (void)uploadPhotoToServerFromImage:(UIImage *)image fileName:(NSString *)flieName success:(nonnull CompleteHandle)success fail:(nonnull CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"上传中" maskType:SVProgressHUDMaskTypeClear];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.5f);
    [HttpHelper uploadFileFormPostWithImageData:imageData fileName:MenuPic success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"上传成功"];
            success(responseObject);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"上传失败"];
    }];
}

@end
